package nancal.mp.db.mysql.table

import java.io.*
import nbcp.base.db.*
import nbcp.base.comm.*
import nbcp.base.extend.*
import nbcp.base.enums.*
import nbcp.base.utils.*
import nbcp.myoql.db.*
import nbcp.myoql.annotation.*
import nbcp.myoql.db.sql.*
import nbcp.myoql.db.comm.*
import nbcp.myoql.db.enums.*
import nbcp.myoql.db.sql.base.*
import nbcp.myoql.db.sql.enums.*
import nbcp.myoql.db.sql.define.*
import nbcp.myoql.db.sql.component.*
import org.springframework.stereotype.*



@Component("sql.admin")
@MetaDataGroup(DatabaseEnum.Rdb, "admin")
class AdminGroup: IDataGroup {
    override fun getEntities(): Set<BaseMetaData<out Any>> = setOf(admin_login_user,admin_user)

    /**
     * 管理员登录信息
     */
    val admin_login_user get() = admin_login_user_table();

    /**
     * 管理员用户信息
     */
    val admin_user get() = admin_user_table();


    /**
     * 管理员登录信息
     */
    @nbcp.base.db.annotation.Cn(value = """管理员登录信息""")
    @nbcp.myoql.db.sql.annotation.AutoIdColumn()
    @nbcp.base.db.annotation.DbEntityIndex(value = arrayOf("""id"""), unique = true)
    open class admin_login_user_table(tableName: String = ""):
        SqlBaseMetaTable<nancal.mp.db.mysql.entity.admin_login_user>(nancal.mp.db.mysql.entity.admin_login_user::class.java, tableName) {
        val userId = SqlColumnName(DbType.STRING, tableName,"user_id", "userId")
        val loginName = SqlColumnName(DbType.STRING, tableName,"login_name", "loginName")
        val mobile = SqlColumnName(DbType.STRING, tableName,"mobile", "mobile")
        val email = SqlColumnName(DbType.STRING, tableName,"email", "email")
        val password = SqlColumnName(DbType.STRING, tableName,"password", "password")
        val lastLoginAt = SqlColumnName(DbType.DATE_TIME, tableName,"last_login_at", "lastLoginAt")
        val isLocked = SqlColumnName(DbType.BOOLEAN, tableName,"is_locked", "isLocked")
        val lockedRemark = SqlColumnName(DbType.STRING, tableName,"locked_remark", "lockedRemark")
        val errorLoginTimes = SqlColumnName(DbType.BYTE, tableName,"error_login_times", "errorLoginTimes")
        val createAt = SqlColumnName(DbType.DATE_TIME, tableName,"create_at", "createAt")
        val updateAt = SqlColumnName(DbType.DATE_TIME, tableName,"update_at", "updateAt")
        val id = SqlColumnName(DbType.STRING, tableName,"id", "id")

        override fun getAutoIncrementKey(): String { return ""}
        override fun getUks(): Array<Array<String>>{ return arrayOf( arrayOf("id")  )}
        override fun getFks(): Array<FkDefine>{ return arrayOf()}


        fun queryById (id: String): SqlQueryClip<admin_login_user_table, nancal.mp.db.mysql.entity.admin_login_user> {
            return this.query().where { it.id sqlEquals id }
        }


        fun deleteById (id: String): SqlDeleteClip<admin_login_user_table> {
            return this.delete().where { it.id sqlEquals id }
        }

        fun updateById (id: String): SqlUpdateClip<admin_login_user_table> {
            return this.update().where { it.id sqlEquals id }
        }

    }
    /**
     * 管理员用户信息
     */
    @nbcp.base.db.annotation.Cn(value = """管理员用户信息""")
    @nbcp.myoql.db.sql.annotation.AutoIdColumn()
    @nbcp.base.db.annotation.DbEntityIndex(value = arrayOf("""id"""), unique = true)
    open class admin_user_table(tableName: String = ""):
        SqlBaseMetaTable<nancal.mp.db.mysql.entity.admin_user>(nancal.mp.db.mysql.entity.admin_user::class.java, tableName) {
        val name = SqlColumnName(DbType.STRING, tableName,"name", "name")
        val loginName = SqlColumnName(DbType.STRING, tableName,"login_name", "loginName")
        val mobile = SqlColumnName(DbType.STRING, tableName,"mobile", "mobile")
        val email = SqlColumnName(DbType.STRING, tableName,"email", "email")
        val remark = SqlColumnName(DbType.STRING, tableName,"remark", "remark")
        val isAdmin = SqlColumnName(DbType.BOOLEAN, tableName,"is_admin", "isAdmin")
        val address = SqlColumnName(DbType.STRING, tableName,"address", "address")
        val createAt = SqlColumnName(DbType.DATE_TIME, tableName,"create_at", "createAt")
        val updateAt = SqlColumnName(DbType.DATE_TIME, tableName,"update_at", "updateAt")
        val id = SqlColumnName(DbType.STRING, tableName,"id", "id")

        override fun getAutoIncrementKey(): String { return ""}
        override fun getUks(): Array<Array<String>>{ return arrayOf( arrayOf("id")  )}
        override fun getFks(): Array<FkDefine>{ return arrayOf()}


        fun queryById (id: String): SqlQueryClip<admin_user_table, nancal.mp.db.mysql.entity.admin_user> {
            return this.query().where { it.id sqlEquals id }
        }


        fun deleteById (id: String): SqlDeleteClip<admin_user_table> {
            return this.delete().where { it.id sqlEquals id }
        }

        fun updateById (id: String): SqlUpdateClip<admin_user_table> {
            return this.update().where { it.id sqlEquals id }
        }

    }
}

